//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Windows.Media;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class FontCollection : IOfficeXmlSerializableAs
    {
        private FontFamily cs;
        private FontFamily ea;
        private FontFamily latin;
        private List<SupplementalFont> supplementalFonts = new List<SupplementalFont>();

        public FontFamily Latin
        {
            get { return latin; }
            set { latin = value; }
        }

        public FontFamily EastAsian
        {
            get { return ea; }
            set { ea = value; }
        }

        public FontFamily ComplexScript
        {
            get { return cs; }
            set { cs = value; }
        }

        public List<SupplementalFont> SupplementalFonts
        {
            get { return supplementalFonts; }
            set { supplementalFonts = value; }
        }

        #region IOfficeXmlSerializableAs Members

        void IOfficeXmlSerializableAs.ReadXmlAs(string name, ReadContext context)
        {
            using (var c = context.Read(name))
            {
                Latin = TextFont.ReadFontfamily("latin", c);
                EastAsian = TextFont.ReadFontfamily("ea", c);
                ComplexScript = TextFont.ReadFontfamily("cs", c);
                while (c.ReaderLocalName == "font")
                {
                    SupplementalFonts.Add(c.ReadElement<SupplementalFont>());
                }
                c.WarnIf("ext");
            }
        }

        void IOfficeXmlSerializableAs.WriteXmlAs(string name, WriteContext context)
        {
            using (WriteContext c = context.Write(name))
            {
                TextFont.WriteFontFamily(Latin, "latin", c);
                TextFont.WriteFontFamily(EastAsian, "ea", c);
                TextFont.WriteFontFamily(ComplexScript, "cs", c);
                foreach (SupplementalFont f in SupplementalFonts)
                    c.WriteElement(f);
                c.WarnIf("ext");
            }
        }

        #endregion
    }
}